# Contributor: wener <wenermail@gmail.com>
# Maintainer: wener <wenermail@gmail.com>
pkgname=grpc
pkgver=1.31.1
pkgrel=0
pkgdesc="The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)"
url="https://grpc.io/"
arch="all !ppc64le !armv7"
license="Apache-2.0"
depends="protobuf"
makedepends="autoconf automake libtool libstdc++ protobuf-dev c-ares-dev
	openssl-dev gtest-dev zlib-dev yaml-dev linux-headers cmake libexecinfo-dev"
subpackages="$pkgname-dev $pkgname-cli"
_googletest_rev=c9ccac7cb7345901884aabf5d1a786cfa6e2f397
_abseil_cpp_rev=df3ea785d8c30a9503321a3d35ee7d35808f190d
_re2_rev=aecba11114cf1fac5497aeb844b6966106de3eb6
_gflags_rev=28f50e0fed19872e0fd50dd23ce2ee8cd759338e
_benchmark_ver=1.5.1
source="$pkgname-$pkgver.tar.gz::https://github.com/grpc/grpc/archive/v$pkgver.tar.gz
		googletest-$_googletest_rev.tar.gz::https://github.com/google/googletest/archive/$_googletest_rev.tar.gz
		abseil-cpp-$_abseil_cpp_rev.tar.gz::https://github.com/abseil/abseil-cpp/archive/$_abseil_cpp_rev.tar.gz
		benchmark-$_benchmark_ver.tar.gz::https://github.com/google/benchmark/archive/v$_benchmark_ver.tar.gz
		re2-$_re2_rev.tar.gz::https://github.com/google/re2/archive/$_re2_rev.tar.gz
		gflags-$_gflags_rev.tar.gz::https://github.com/gflags/gflags/archive/$_gflags_rev.tar.gz
		01-chttp2-maybe-uninitialized.patch
		"
options="!check"

unpack() {
	default_unpack
	cd "$srcdir"
	rm -rf $pkgname-$pkgver/third_party/googletest
	ln -sfn $PWD/googletest-$_googletest_rev/ $pkgname-$pkgver/third_party/googletest

	rm -rf $pkgname-$pkgver/third_party/abseil-cpp
	ln -sfn $PWD/abseil-cpp-$_abseil_cpp_rev/ $pkgname-$pkgver/third_party/abseil-cpp

	rm -rf $pkgname-$pkgver/third_party/benchmark
	ln -sfn $PWD/benchmark-$_benchmark_ver/ $pkgname-$pkgver/third_party/benchmark

	rm -rf $pkgname-$pkgver/third_party/re2
	ln -sfn $PWD/re2-$_re2_rev/ $pkgname-$pkgver/third_party/re2

	rm -rf $pkgname-$pkgver/third_party/gflags
	ln -sfn $PWD/gflags-$_gflags_rev/ $pkgname-$pkgver/third_party/gflags
}

build() {
	mkdir -p cmake/build
	cd cmake/build
	# gRPC_BUILD_TESTS for grpc_cli - very slow
	cmake ../..                        \
	  -DgRPC_INSTALL=ON                \
	  -DgRPC_CARES_PROVIDER=package    \
	  -DgRPC_PROTOBUF_PROVIDER=package \
	  -DgRPC_SSL_PROVIDER=package      \
	  -DgRPC_ZLIB_PROVIDER=package     \
	  -DBUILD_TESTING=OFF              \
	  -DgRPC_BUILD_TESTS=ON            \
	  -DCMAKE_INSTALL_PREFIX="$pkgdir/usr"
	make
	make grpc_cli
}

package() {
	cd cmake/build
	make install
	cp grpc_cli $pkgdir/usr/bin/
	rm -f "$pkgdir/usr/share/grpc/roots.pem"
}

cli() {
	pkgdesc="gRPC command line tool"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/grpc_cli "$subpkgdir"/usr/bin/
}

sha512sums="a4ac3801b65707b4cbdc50d0ded81f1e6546df7b8135700a8d97c4917f0a7c6b8e2d348b1dfb36cb8627f5e5d3f06fe356e0fdec7954e8a2af87ecca2c663245  grpc-1.31.1.tar.gz
7dda1e090d5054896899a250433d78ba9fcc004a60c886c93098c726ff12f70bb8d222112f8845e98c1ceacdb060b96699bb90d8f4207496546996195ae90343  googletest-c9ccac7cb7345901884aabf5d1a786cfa6e2f397.tar.gz
b429758c37749d3d5c5c220fe0dc00fa0e193b406545484095339b25674c4a3bb7850b76dd1a370ed2006729bcbbbb1b438995b614e149c2290bdb10038c49d1  abseil-cpp-df3ea785d8c30a9503321a3d35ee7d35808f190d.tar.gz
1e8782ab6846b8b29c5eea41ed1ba19dd92a46a135cf74acdc588e2cd5ef05581c644d20fc0d6403456d65417538e1db80109ae87989601298b2fc56ae3c3161  benchmark-1.5.1.tar.gz
bbe972e3fd65da69e0d7ac0e0b025fb09ad894315cb6c0e1268fa296599274f9f7c2e771aa577b340c8fa9412d8539fe3db2171d0e9ab9714f3f10910a1d5529  re2-aecba11114cf1fac5497aeb844b6966106de3eb6.tar.gz
f43f3ae6ad172999f3cc2943a81563ad94598b896f29efeebb26948d559bbe78fc2c6ad6719385473387885240ccee68769fd7ceacf7b6a79057b6c8622e2079  gflags-28f50e0fed19872e0fd50dd23ce2ee8cd759338e.tar.gz
7fa146ce86ddd4f160bb1ca9ff01cb7aca6b2b8c9aa50e4fa6b84504b9117b104be0d1e31ccb452d846549dfe1e9012ceccfcdc1f2357ed567621d71fb8b08c5  01-chttp2-maybe-uninitialized.patch"
